package com.zero.mxshengadmin.modules.website.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zero.mxshengadmin.common.exception.RRException;
import com.zero.mxshengadmin.modules.website.dao.WebsiteBannerDao;
import com.zero.mxshengadmin.modules.website.entity.WebsiteAdvertiseEntity;
import com.zero.mxshengadmin.modules.website.entity.WebsiteBannerEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteBannerService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * Created by aicaikeji on 2019/4/3.
 */

@Service("websiteBannerService")
public class WebsiteBannerServiceImpl extends ServiceImpl<WebsiteBannerDao,WebsiteBannerEntity> implements WebsiteBannerService {
    /**
     * 添加一个banner
     * @param entity
     * @return
     */
    @Override
    public void save(WebsiteBannerEntity entity) {
        boolean save = this.insert(entity);
        if (!save) throw new RRException("操作失败");
    }

    /**
     * 修改一个banner
     * @param entity
     * @return
     */
    @Override
    public void update(WebsiteBannerEntity entity) {
        boolean update = this.updateById(entity);
        if (!update) throw new RRException("操作失败");
    }

    /**
     * 查询轮播详情
     * @param id
     * @return
     */
    @Override
    public WebsiteBannerEntity getById(long id) {
        WebsiteBannerEntity entity = this.selectById(id);
        if (entity == null) {
            throw  new RRException("操作失败");
        }else {
            return entity;
        }
    }

    /**
     * 删除一个banner
     * @param ids
     * @return
     */
    @Override
    public void removeByIds(Long[] ids) {
        this.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 查询banner列表
     * @return
     */
    @Override
    public List<WebsiteBannerEntity> list() {
        return this.selectList(new EntityWrapper<>());
    }

}
